package com.exmaple.deal.filter;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import com.netflix.zuul.FilterFileManager;
import com.netflix.zuul.FilterLoader;
import com.netflix.zuul.groovy.GroovyCompiler;
import com.netflix.zuul.groovy.GroovyFileFilter;
import com.netflix.zuul.monitoring.MonitoringHelper;


@Component
  public  class GroovyCommandLineRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
      MonitoringHelper.initMocks();
      FilterLoader.getInstance().setCompiler(new GroovyCompiler());
      try {
        FilterFileManager.setFilenameFilter(new GroovyFileFilter());
        String basePath = ClassUtils.getDefaultClassLoader().getResource("").getPath()+"filters/";
        FilterFileManager.init(1, basePath + "pre", basePath + "post");
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }